package com.taotao.product.controller;

import com.taotao.common.core.domain.Result;
import com.taotao.common.core.utils.poi.ExcelUtil;
import com.taotao.common.core.web.controller.BaseController;
import com.taotao.common.core.web.page.TableDataInfo;
import com.taotao.common.log.annotation.Log;
import com.taotao.common.log.enums.BusinessType;
import com.taotao.common.security.annotation.RequiresPermissions;
import com.taotao.product.domain.PmsAttr;
import com.taotao.product.service.IPmsAttrService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品属性Controller
 *
 * @author ccy
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/attr")
public class PmsAttrController extends BaseController
{
    @Autowired
    private IPmsAttrService pmsAttrService;

    /**
     * 查询商品属性列表
     */
    @RequiresPermissions("product:attr:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(PmsAttr pmsAttr)
    {
        startPage();
        List<PmsAttr> list = pmsAttrService.selectPmsAttrList(pmsAttr);
        return getDataTable(list);
    }


    /**
     * 获取商品属性详细信息
     */
    @RequiresPermissions("product:attr:query")
    @GetMapping(value = "/{attrId}")
    public Result getInfo(@PathVariable("attrId") Long attrId)
    {
        return success(pmsAttrService.selectPmsAttrByAttrId(attrId));
    }

    /**
     * 新增商品属性
     */
    @RequiresPermissions("product:attr:add")
    @Log(title = "商品属性", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody PmsAttr pmsAttr)
    {
        return toAjax(pmsAttrService.insertPmsAttr(pmsAttr));
    }

    /**
     * 修改商品属性
     */
    @RequiresPermissions("product:attr:edit")
    @Log(title = "商品属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody PmsAttr pmsAttr)
    {
        return toAjax(pmsAttrService.updatePmsAttr(pmsAttr));
    }

    /**
     * 删除商品属性
     */
    @RequiresPermissions("product:attr:remove")
    @Log(title = "商品属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attrIds}")
    public Result remove(@PathVariable Long[] attrIds)
    {
        return toAjax(pmsAttrService.deletePmsAttrByAttrIds(attrIds));
    }
}
